﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class _RoughShankCuttingTaps1
    {
        public static void RoughShankCuttingTaps1(Dictionary<string, Object> data)//粗柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
                                                                           //参数
            double fdc = Convert.ToDouble(data["fdc"]);
            string path = Convert.ToString(data["path"]);
            string code = Convert.ToString(data["tdz"]);
            // 非空判断
            if (data["lu"].Equals("")) data["lu"] = 0;
            if (data["dn"].Equals("")) data["dn"] = 0;
            if (fdc == 0)
            {
                //作图
                //参数
                double soal = Convert.ToDouble(data["oal"]);
                double scale = Convert.ToDouble(data["scale"]); //放大系数
                if (scale == 0 && soal < 105)
                {
                    scale = 2.0;
                }
                else if (scale == 0 && soal < 210)
                {
                    scale = 1.0;
                }
                else if (scale == 0)
                {
                    scale = 0.5;
                }
                double pi = Math.PI;
                double td = Convert.ToDouble(data["td"]) * scale;
                double dmm = Convert.ToDouble(data["dconms"]) * scale;
                double tp = Convert.ToDouble(data["tp"]) * scale;
                double dn = Convert.ToDouble(data["dn"]) * scale;
                if (dn == 0)
                {
                    dn = td - 1.1325 * tp - 0.15;
                }
                double mc = Convert.ToDouble(data["mc"]);
                double qxzj;
                if (mc == 0)
                {
                    qxzj = 4.5 * pi / 180;
                }
                if (mc == 1)
                {
                    qxzj = 8.5 * pi / 180;
                }
                if (mc == 2)
                {
                    qxzj = 17 * pi / 180;
                }
                else
                {
                    qxzj = 6 * pi / 180;
                }

                double tcl;
                if (mc == 0)
                {
                    tcl = 8 * tp;
                }
                else if (mc == 1)
                {
                    tcl = 4 * tp;
                }
                else if (mc == 2)
                {
                    tcl = 2 * tp;
                }
                else
                {
                    tcl = 6 * tp;
                }

                if (tcl == 0)
                {
                    tcl = tp * 2.3;
                }
                double tcpd = td - tcl * Math.Tan(qxzj);
                double wcf = Convert.ToDouble(data["wcf"]) * scale;
                if (wcf == 0)
                {
                    wcf = td / 3;
                }
                double thl = Convert.ToDouble(data["thl"]) * scale;
                double lu = Convert.ToDouble(data["lu"]) * scale;
                if (lu == 0)
                {
                    lu = thl * 39 / 22;
                }
                double oal = Convert.ToDouble(data["oal"]) * scale;
                double drvsc = Convert.ToDouble(data["drvsc"]) * scale;
                double drvl = Convert.ToDouble(data["drvl"]) * scale;
                double sig = Convert.ToDouble(data["sig"]) * pi / 180;
                double ta = Convert.ToDouble(data["ta"]) * pi / 180;
                double ds = dmm - 0.08 * scale;//柄方外圆
                double ds1 = dmm * 1 / 10.0;
                double isframe = Convert.ToDouble(data["isframe"]);
                //坐标
                //主视图
                Vector2 v2 = new Vector2(-oal / 2.00, tcpd / 2.00);
                Vector2 v1 = new Vector2(v2.X - v2.Y / Math.Tan(sig / 2.00), 0);
                Vector2 v3 = new Vector2(v2.X + tcl, td / 2.00);
                Vector2 v4 = new Vector2(v2.X + thl, v3.Y);
                Vector2 v5 = new Vector2((td - dn) / 2.00 + v4.X, dn / 2.00);
                Vector2 v6 = new Vector2(v2.X + lu, v5.Y);
                Vector2 p7_1 = fun.Polar(v1, pi / 2, dmm / 2.0);
                Vector2 p7_2 = fun.Polar(p7_1, 0, oal);
                Vector2 v7;
                if (v6.Y == dmm / 2.0)
                {
                    v7 = v6;
                }
                else if (v6.Y < dmm / 2.0)
                {
                    v7 = fun.Inters(p7_1, p7_2, v6, fun.Polar(v6, pi / 4, oal));
                }
                else
                {
                    v7 = fun.Inters(p7_1, p7_2, v6, fun.Polar(v6, pi / -4, oal));
                }
                //Vector2 v7 = new Vector2((dmm - dn) / 2.00 / Math.Tan(ta) + v6.X, dmm / 2.00);
                Vector2 v8 = new Vector2(v2.X + oal - 0.15 * dmm, ds / 2);
                Vector2 v9 = new Vector2(v2.X + oal, 0.35 * dmm);
                Vector2 v10 = new Vector2(v9.X, -v9.Y);
                Vector2 v11 = new Vector2(v8.X, -v8.Y);
                Vector2 v12 = new Vector2(v7.X, -v7.Y);
                Vector2 v13 = new Vector2(v6.X, -v6.Y);
                Vector2 v14 = new Vector2(v5.X, -v5.Y);
                Vector2 v15 = new Vector2(v4.X, -v4.Y);
                Vector2 v16 = new Vector2(v3.X, -v3.Y);
                Vector2 v17 = new Vector2(v2.X, -v2.Y);
                Vector2 v19 = new Vector2(v8.X - drvl, ds1);
                Vector2 v18 = fun.Inters(v7, v8, v19, fun.Polar(v19, pi / 2, 150));
                Vector2 v20 = new Vector2(v8.X, v19.Y);
                Vector2 v21 = new Vector2(v20.X, v18.Y);
                Vector2 v22 = new Vector2(v21.X - (v18.Y - v19.Y) / 2.00 * Math.Tan(60 * pi / 180), (v18.Y + v19.Y) / 2.00);
                Vector2 v23 = new Vector2(v18.X, -v18.Y);
                Vector2 v24 = new Vector2(v19.X, -v19.Y);
                Vector2 v25 = new Vector2(v20.X, -v20.Y);
                Vector2 v26 = new Vector2(v21.X, -v21.Y);
                Vector2 v27 = new Vector2(v22.X, -v22.Y);
                Vector2 v28 = new Vector2(v2.X + lu - 3, 0);
                Vector2 v29 = new Vector2(v2.X + lu - 2 * wcf / 3.00 - 3, wcf / 3.00);
                Vector2 v30 = new Vector2(v2.X + lu - 3 * wcf / 2.00 - 3, wcf / 2.00);
                Vector2 v31 = new Vector2(v30.X, -v30.Y);
                Vector2 v32 = new Vector2(v29.X, -v29.Y);
                Vector2 v33 = new Vector2(v2.X, v30.Y);
                Vector2 v34 = new Vector2(v33.X, -v33.Y);
                double dx = v2.X;
                if (tcpd < dn)
                {
                    dx = (v5.Y - oal * (td - tcpd) / 4 / tcl - tcpd / 2) * 2 * tcl / (td - tcpd);
                }
                Vector2 v35 = new Vector2(dx, v5.Y);
                Vector2 v36 = new Vector2(dx, v14.Y);
                Vector2 v37 = new Vector2(v4.X, v34.Y);
                Vector2 v38 = new Vector2(v37.X, -v37.Y);
                Vector2 v39 = new Vector2(v5.X, v38.Y);
                Vector2 v40 = new Vector2(v39.X, -v39.Y);
                Vector2 v41 = new Vector2(v1.X - 2, v1.Y);
                Vector2 v42 = new Vector2(v9.X + 2, v1.Y);
                Vector2 v43 = new Vector2(2 * v1.X - v17.X, v2.Y);
                Vector2 v44 = new Vector2(2 * v1.X - v2.X, v17.Y);
                Vector2 v80 = new Vector2(v8.X - drvl - 1 * scale, v7.Y);
                Vector2 v81 = new Vector2(v80.X, -v80.Y);
                Vector2 v82 = new Vector2(v80.X, ds / 2.00);
                Vector2 v83 = new Vector2(v82.X, -v82.Y);
                //柄方
                Vector2 v45 = new Vector2(oal + oal / 15.00, v8.Y - (v20.Y - v25.Y) * Math.Cos(45 * pi / 180));
                Vector2 v46 = new Vector2(v45.X - (v20.Y - v25.Y) / 2.00, v45.Y + (v20.Y - v25.Y) / 2.00);
                Vector2 v47 = new Vector2(v45.X * 2 - v46.X, v46.Y);
                Vector2 v48 = new Vector2(v45.X + v45.Y, v1.Y);
                Vector2 v49 = new Vector2(v45.X + v46.Y, v48.Y + v47.X - v45.X);
                Vector2 v50 = new Vector2(v49.X, -v49.Y);
                Vector2 v51 = new Vector2(v45.X, -v45.Y);
                Vector2 v52 = new Vector2(v47.X, -v47.Y);
                Vector2 v53 = new Vector2(v46.X, -v46.Y);
                Vector2 v54 = new Vector2(v45.X * 2 - v48.X, v48.Y);
                Vector2 v55 = new Vector2(v45.X * 2 - v50.X, v50.Y);
                Vector2 v56 = new Vector2(v45.X * 2 - v49.X, v49.Y);
                Vector2 v57 = new Vector2(v45.X - ds / 2.00 - 2, 0);
                Vector2 v58 = new Vector2(v45.X + ds / 2.00 + 2, 0);
                Vector2 v59 = new Vector2(v45.X, ds / 2.00 + 2);
                Vector2 v60 = new Vector2(v59.X, -v59.Y);
                string tctr = Convert.ToString(data["tctr"]);
                //检测
                /*
                Vector2[] v1000 = { v1, v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20
                    ,v21,v22,v23,v24,v25,v26,v27,v28,v29,v30,v31,v32,v33,v34,v35,v36,v37,v38,v39,v40,v41,v42,v43,v44
                ,v45,v46,v47,v48,v49,v50,v51,v52,v53,v54,v55,v56,v57,v58,v59,v60,v80,v81,v82,v83};
               
                fun.seevector2(dxf,0.6,v1000);//计算各个点
                */

                if (!tctr.Equals("0"))
                {
                    Vector2 a1 = fun.Polar(v3, fun.CalAngle(v3, v4), fun.CalDistance(v3, v4) / 2);
                    Vector2 a2 = fun.Polar(a1, 45 * pi / 180, 15);
                    Vector2 a3 = fun.Polar(a1, 45 * pi / 180, 16);
                    Line line101 = new Line(a1, a2);
                    dxf.AddEntity(line101);
                    fun.text(dxf, a3, 2, "丝锥公差带:" + tctr + "");
                }
                //线段
                //主视图
                Vector2[] Line1 = { v1, v2 };
                fun.drawBLine(dxf, Line1, 0.3, contour);
                Vector2[] Line2 = { v2, v3 };
                fun.drawBLine(dxf, Line2, 0.3, contour);
                Vector2[] Line3 = { v3, v4 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line4 = { v4, v5 };
                fun.drawBLine(dxf, Line4, 0.3, contour);
                Vector2[] Line5 = { v5, v6 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
                Vector2[] Line6 = { v6, v7 };
                fun.drawBLine(dxf, Line6, 0.3, contour);
                Vector2[] Line7 = { v7, v80 };
                fun.drawBLine(dxf, Line7, 0.3, contour);
                Vector2[] Line8 = { v8, v9 };
                fun.drawBLine(dxf, Line8, 0.3, contour);
                Vector2[] Line9 = { v9, v10 };
                fun.drawBLine(dxf, Line9, 0.3, contour);
                Vector2[] Line10 = { v10, v11 };
                fun.drawBLine(dxf, Line10, 0.3, contour);
                Vector2[] Line11 = { v81, v12 };
                fun.drawBLine(dxf, Line11, 0.3, contour);
                Vector2[] Line12 = { v12, v13 };
                fun.drawBLine(dxf, Line12, 0.3, contour);
                Vector2[] Line13 = { v13, v14 };
                fun.drawBLine(dxf, Line13, 0.3, contour);
                Vector2[] Line14 = { v14, v15 };
                fun.drawBLine(dxf, Line14, 0.3, contour);
                Vector2[] Line15 = { v15, v16 };
                fun.drawBLine(dxf, Line15, 0.3, contour);
                Vector2[] Line16 = { v16, v17 };
                fun.drawBLine(dxf, Line16, 0.3, contour);
                Vector2[] Line17 = { v17, v1 };
                fun.drawBLine(dxf, Line17, 0.3, contour);
                Vector2[] Line18 = { v2, v17 };
                fun.drawBLine(dxf, Line18, 0.3, contour);
                Vector2[] Line19 = { v4, v38 };
                fun.drawBLine(dxf, Line19, 0.3, contour);
                Vector2[] Line20 = { v37, v15 };
                fun.drawBLine(dxf, Line20, 0.3, contour);
                Vector2[] Line21 = { v5, v39 };
                fun.drawBLine(dxf, Line21, 0.3, contour);
                Vector2[] Line22 = { v40, v14 };
                fun.drawBLine(dxf, Line22, 0.3, contour);
                Vector2[] Line23 = { v6, v13 };
                fun.drawBLine(dxf, Line23, 0.3, contour);
                Vector2[] Line24 = { v7, v12 };
                fun.drawBLine(dxf, Line24, 0.3, contour);
                Vector2[] Line25 = { v8, v21 };
                fun.drawBLine(dxf, Line25, 0.3, contour);
                Vector2[] Line26 = { v20, v25 };
                fun.drawBLine(dxf, Line26, 0.3, contour);
                Vector2[] Line27 = { v26, v11 };
                fun.drawBLine(dxf, Line27, 0.3, contour);
                Vector2[] Line28 = { v21, v18 };
                fun.drawBLine(dxf, Line28, 0.3, contour);
                Vector2[] Line29 = { v18, v19 };
                fun.drawBLine(dxf, Line29, 0.3, contour);
                Vector2[] Line30 = { v19, v20 };
                fun.drawBLine(dxf, Line30, 0.3, contour);
                Vector2[] Line31 = { v25, v24 };
                fun.drawBLine(dxf, Line31, 0.3, contour);
                Vector2[] Line32 = { v24, v23 };
                fun.drawBLine(dxf, Line32, 0.3, contour);
                Vector2[] Line33 = { v23, v26 };
                fun.drawBLine(dxf, Line33, 0.3, contour);
                //Arc Arc1 = new Arc(v22, (v18.Y - v19.Y) / 2.00 / Math.Cos(60 * pi / 180), -30, 30);
                //Arc Arc2 = new Arc(v27, (v18.Y - v19.Y) / 2.00 / Math.Cos(60 * pi / 180), -30, 30);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(v21));
                Arc1.Vertexes.Add(new LwPolylineVertex(v20));
                Arc1.Vertexes[0].Bulge = -((v21.Y - v20.Y) / 2.00 / Math.Cos(60 * pi / 180) - v21.X + v22.X) / ((v21.Y - v20.Y) / 2.00);
                fun.PolyFill(dxf, Arc1, 0.3, contour);
                LwPolyline Arc2 = new LwPolyline();
                Arc2.Vertexes.Add(new LwPolylineVertex(v25));
                Arc2.Vertexes.Add(new LwPolylineVertex(v26));
                Arc2.Vertexes[0].Bulge = -((v21.Y - v20.Y) / 2.00 / Math.Cos(60 * pi / 180) - v21.X + v22.X) / ((v21.Y - v20.Y) / 2.00);
                fun.PolyFill(dxf, Arc2, 0.3, contour);
                /* LwPolyline Arc4 = new LwPolyline();
                 Arc4.Vertexes.Add(new LwPolylineVertex(v18));
                 Arc4.Vertexes.Add(new LwPolylineVertex(v19));
                 Arc4.Vertexes[0].Bulge = 1 * scale / ((v18.Y - v19.Y) / 2.00);
                fun.PolyFill(dxf, Arc4, 0.3, contour);*/
                Vector2 v61 = fun.Polar(v18, pi, oal * (1.5 / 194.5));
                Vector2 v64 = fun.Polar(v61, pi / -2 + 0.01 * pi / 180, oal);
                Line line11 = new Line(v61, v64);
                Arc arc1 = fun.DrawArc5(v18, line11, v19);
                Arc arc2 = fun.DrawArc5(v24, line11, v23);
                fun.drawBArc(dxf, arc1, 0.3, contour);
                fun.drawBArc(dxf, arc2, 0.3, contour);
                /* LwPolyline Arc5 = new LwPolyline();
                 Arc5.Vertexes.Add(new LwPolylineVertex(v24));
                 Arc5.Vertexes.Add(new LwPolylineVertex(v23));
                 Arc5.Vertexes[0].Bulge = 1 * scale / ((v24.Y - v23.Y) / 2.00);
                 fun.PolyFill(dxf, Arc5, 0.3, contour);*/
                Line line34 = new Line(v5, v35);
                line34.Lineweight = Lineweight.W25;
                line34.Layer = additionalline;
                dxf.AddEntity(line34);
                Line line35 = new Line(v14, v36);
                line35.Lineweight = Lineweight.W25;
                line35.Layer = additionalline;
                dxf.AddEntity(line35);
                /*Vector2[] Line36 = { v34, v31 };
                fun.drawBLine(dxf, Line36, 0.3, contour);
                Vector2[] Line37 = { v33, v30 };
                fun.drawBLine(dxf, Line37, 0.3, contour);*/
                Line Line36 = new Line(v34, v31);
                Line36.Layer = contour;
                dxf.AddEntity(Line36);
                Line Line37 = new Line(v33, v30);
                Line37.Layer = contour;
                dxf.AddEntity(Line37);
                Vector2[] Line38 = { v41, v42 };
                fun.drawPlinetype(dxf, Line38, 0.15, centre, Linetype.Center);
                Vector2[] Line39 = { v18, v20 };
                fun.drawBLine(dxf, Line39, 0.15, contour);
                Vector2[] Line40 = { v19, v21 };
                fun.drawBLine(dxf, Line40, 0.15, contour);
                Vector2[] Line41 = { v24, v26 };
                fun.drawBLine(dxf, Line41, 0.15, contour);
                Vector2[] Line42 = { v23, v25 };
                fun.drawBLine(dxf, Line42, 0.15, contour);
                Line Line43 = new Line(v1, v43);
                Line Line44 = new Line(v1, v44);
                List<Vector3> point1 = new List<Vector3>
            {
                fun.Tothree(v31),
                fun.Tothree(v32),
                fun.Tothree(v28),
                fun.Tothree(v29),
                fun.Tothree(v30),
            };

                Spline spline1 = new Spline(point1);
                spline1.Layer = contour;
                dxf.AddEntity(spline1);
                //fun.PolyFill(dxf, spline1, 0.3, contour);
                Vector2[] Line55 = { v80, v81 };
                fun.drawBLine(dxf, Line55, 0.3, contour);
                Vector2[] Line56 = { v82, v8 };
                fun.drawBLine(dxf, Line56, 0.3, contour);
                Vector2[] Line57 = { v83, v11 };
                fun.drawBLine(dxf, Line57, 0.3, contour);
                //柄方
                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(v47));
                poly1.Vertexes.Add(new LwPolylineVertex(v49));
                poly1.Vertexes.Add(new LwPolylineVertex(v50));
                poly1.Vertexes[1].Bulge = -Math.Tan(pi / 8);
                poly1.Vertexes.Add(new LwPolylineVertex(v52));
                poly1.Vertexes[3].Bulge = -Math.Tan(pi / 8);
                poly1.Vertexes.Add(new LwPolylineVertex(v53));
                poly1.Vertexes.Add(new LwPolylineVertex(v55));
                poly1.Vertexes[5].Bulge = -Math.Tan(pi / 8);
                poly1.Vertexes.Add(new LwPolylineVertex(v56));
                poly1.Vertexes.Add(new LwPolylineVertex(v46));
                poly1.Vertexes[7].Bulge = -Math.Tan(pi / 8);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.3, contour);
                Line Line53 = new Line(v57, v58);
                Line Line54 = new Line(v59, v60);
                //主视图图层
               // Line43.Layer = dimensioning;
                //Line44.Layer = dimensioning;
                //柄方图层
                Line53.Layer = centre;
                Line54.Layer = centre;
                Line53.Linetype = Linetype.Center;
                Line54.Linetype = Linetype.Center;
                //主视图
               // dxf.AddEntity(Line43);
               // dxf.AddEntity(Line44);
                //柄方
                dxf.AddEntity(Line53);
                dxf.AddEntity(Line54);
                //标注样式
                //箭头样式
                DimensionStyle dimensionStyle = fun.CreateDimStyle();
                dimensionStyle.ArrowSize = 0.5 * (oal / 40);
                dimensionStyle.ExtLineExtend = 0.6 * (oal / 40);//标注延长线长度/2
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                //文本样式
                dimensionStyle.TextHeight = (2.5 * (oal / 40)) / 4.0;
                double offset = 20 * (oal / 40);
                double height = (2.5 * (oal / 40)) / 2.0;
                double arrowsize = 0.5 * (oal / 40);
                //线段尺寸标注
                //尺寸1
                /*
                Angular2LineDimension angdim1 = new Angular2LineDimension(new Line(v1, v43), new Line(v1, v44), offset, dimensionStyle);
                angdim1.UserText = "SIG = " + Math.Round(sig / (pi / 180), 2) + "°";
                dxf.AddEntity(angdim1);*/

                string l5;
                string kr;

                if (mc == 0) { l5 = "8P"; kr = "4°30′"; }
                else if (mc == 1) { l5 = "4P"; kr = "8°30′"; }
                else if (mc == 2) { l5 = "2P"; kr = "17°"; }
                else if (mc == 3) { l5 = "6P"; kr = "6°"; }
                else { l5 = ""; kr = ""; }

                if (mc == 3 && tp > 2.5)
                {
                    Line line01 = new Line(fun.Polar(v80, pi, 4), fun.Polar(v81, pi, 4)); fun.drawBline(dxf, line01, 0.3, contour);
                }
                if (mc == 1 && tp > 2.5)
                {
                    Line line01 = new Line(fun.Polar(v80, pi, 4), fun.Polar(v81, pi, 4)); fun.drawBline(dxf, line01, 0.3, contour);
                    Line line02 = new Line(fun.Polar(v80, pi, 6.5), fun.Polar(v81, pi, 6.5)); fun.drawBline(dxf, line02, 0.3, contour);
                }


               /* LinearDimension dim00 = new LinearDimension(new Line(v3, v2), offset / 2.0, 0, dimensionStyle);
                dim00.UserText = "TCL = " + l5;
                dxf.AddEntity(dim00);*/

                //fun.jdbz2(dxf, new Line(v3, v4), new Line(v2, v3), offset, height, arrowsize, 0.6, "KAPR=" + kr, "", "");
                //  fun.jdbz2(dxf, new Line(v1, v43), new Line(v1, v44), offset /2.0, height, arrowsize , 0.4, "SIG = " + Math.Round(sig / (pi / 180), 2) + "°", "", "");
                //尺寸2
                LinearDimension dim2 = new LinearDimension(new Line(v3, v16), -v3.X + v43.X - offset - 5, 270, dimensionStyle);
                dim2.UserText = "TD = " + Math.Round(td / scale, 2);
                dxf.AddEntity(dim2);
                //尺寸3
                double toh = Convert.ToDouble(data["thltctrh"]);
                double tol = Convert.ToDouble(data["thltctrl"]);
                if (toh == 0 && tol == 0)
                {
                    LinearDimension dim3 = new LinearDimension(new Line(v17, v15), (-offset - 5) / 3.0, 0, dimensionStyle);
                    dim3.UserText = "THL = " + Math.Round(thl / scale, 2);
                    dxf.AddEntity(dim3);
                }
                else
                {
                    fun.dimrot(dxf, v17, v15, 0, -offset * (2 / 3.0), height, arrowsize, 2.5, "THL = " + Math.Round(thl / scale, 2), toh + "", tol + "");
                }
                //尺寸4
                LinearDimension dim4 = new LinearDimension(new Line(v17, v13), -offset * (2 / 3.0), 0, dimensionStyle);
                dim4.UserText = "LU = " + Math.Round(lu / scale, 2);
                dxf.AddEntity(dim4);
                //尺寸5
                double toh1 = Convert.ToDouble(data["oaltctrh"]);
                double tol1 = Convert.ToDouble(data["oaltctrl"]);
                string oaltctr = Convert.ToString(data["oaltctr"]);
                if (toh1 == 0 && tol1 == 0)
                {
                    if (oaltctr.Equals("0"))
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v17, v10), -offset, 0, dimensionStyle);
                        dim5.UserText = "OAL = " + Math.Round(oal / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    else
                    {
                        LinearDimension dim7 = new LinearDimension(new Line(v17, v10), -offset, 0, dimensionStyle);
                        dim7.UserText = "OAL = " + Math.Round(oal / scale, 2) + "  " + oaltctr;
                        dxf.AddEntity(dim7);
                    }
                }
                else
                {
                    fun.dimrot(dxf, v17, v10, 0, -offset, height, arrowsize, 2.5, "OAL = " + Math.Round(oal / scale, 2), toh1 + "", tol1 + "");
                }

                //尺寸6
                LinearDimension dim6 = new LinearDimension(new Line(v23, v26), (-offset - (v26.Y - v11.Y)) / 3.0, 0, dimensionStyle);
                dim6.UserText = "DRVL = " + Math.Round(drvl / scale, 2);
                dxf.AddEntity(dim6);
                //尺寸7
                string tcdconws = Convert.ToString(data["tcdconws"]);
                if (tcdconws.Equals("0"))
                {
                    LinearDimension dim7 = new LinearDimension(new Line(v80, v81), (v9.X - v80.X + offset) / 2.0, 270, dimensionStyle);
                    dim7.UserText = "DCONMS = " + Math.Round(dmm / scale, 2);
                    dxf.AddEntity(dim7);
                }
                else
                {
                    LinearDimension dim7 = new LinearDimension(new Line(v80, v81), (v9.X - v80.X + offset) / 2.0, 270, dimensionStyle);
                    dim7.UserText = "DCONMS = " + Math.Round(dmm / scale, 2) + "  " + tcdconws;
                    dxf.AddEntity(dim7);
                }


                //尺寸8
                LinearDimension dim8 = new LinearDimension(new Line(v46, v50), -offset / 2.0, 135, dimensionStyle);
                dim8.UserText = "DRVSC = " + Math.Round(drvsc / scale, 2);
                dxf.AddEntity(dim8);
                //填充
                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v47));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v49));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v50));
                hatchpoly1.Vertexes[1].Bulge = -Math.Tan(pi / 8);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v52));
                hatchpoly1.Vertexes[3].Bulge = -Math.Tan(pi / 8);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v53));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v55));
                hatchpoly1.Vertexes[5].Bulge = -Math.Tan(pi / 8);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v56));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v46));
                hatchpoly1.Vertexes[7].Bulge = -Math.Tan(pi / 8);
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 89, 2.5 * (td / 3.0), hline1, harc1, hatching);
                //图框
                if (isframe == 1)
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(v1.X - 210 + (v45.X + v8.Y - v1.X) / 2.00, v1.Y + 148.5), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }
            else if (fdc == 1)
            {
                double soal = Convert.ToDouble(data["oal"]);
                double scale = Convert.ToDouble(data["scale"]); //放大系数
                if (scale == 0 && soal < 105)
                {
                    scale = 2.0;
                }
                else if (scale == 0 && soal < 210)
                {
                    scale = 1.0;
                }
                else if (scale == 0)
                {
                    scale = 0.5;
                }
                double pi = Math.PI;
                double td = Convert.ToDouble(data["td"]) * scale;
                double dmm = Convert.ToDouble(data["dmm"]) * scale;
                double tp = Convert.ToDouble(data["tp"]) * scale;
                double dn = Convert.ToDouble(data["dn"]) * scale;
                if (dn == 0)
                {
                    dn = td - 1.1325 * tp - 0.15;
                }
                double mc = Convert.ToDouble(data["mc"]);
                double qxzj;
                if (mc == 0)
                {
                    qxzj = 4.5 * pi / 180;
                }
                if (mc == 1)
                {
                    qxzj = 8.5 * pi / 180;
                }
                if (mc == 2)
                {
                    qxzj = 17 * pi / 180;
                }
                else
                {
                    qxzj = 6 * pi / 180;
                }

                double tcl;
                if (mc == 0)
                {
                    tcl = 8 * tp;
                }
                else if (mc == 1)
                {
                    tcl = 4 * tp;
                }
                else if (mc == 2)
                {
                    tcl = 2 * tp;
                }
                else
                {
                    tcl = 6 * tp;
                }

                if (tcl == 0)
                {
                    tcl = tp * 2.3;
                }
                double tcpd = td - tcl * Math.Tan(qxzj);
                double thl = Convert.ToDouble(data["thl"]) * scale;
                double lu = Convert.ToDouble(data["lu"]) * scale;
                if (lu == 0)
                {
                    lu = thl * 39 / 22;
                }
                double oal = Convert.ToDouble(data["oal"]) * scale;
                double drvsc = Convert.ToDouble(data["drvsc"]) * scale;
                double drvl = Convert.ToDouble(data["drvl"]) * scale;
                double sig = Convert.ToDouble(data["sig"]) * pi / 180;
                double FHA = Convert.ToDouble(data["fha"]);
                double ta = Convert.ToDouble(data["ta"]) * pi / 180;
                double ds = dmm - 0.08 * scale;//柄方外圆
                double ds1 = dmm * 1 / 10.0;
                double isframe = Convert.ToDouble(data["isframe"]);
                //坐标
                //主视图
                Vector2 v2 = new Vector2(-oal / 2.00, tcpd / 2.00);
                Vector2 v1 = new Vector2(v2.X - v2.Y / Math.Tan(sig / 2.00), 0);
                Vector2 v3 = new Vector2(v2.X + tcl, td / 2.00);
                Vector2 v4 = new Vector2(v2.X + thl, v3.Y);
                Vector2 v5 = new Vector2((td - dn) / 2.00 + v4.X, dn / 2.00);
                Vector2 v6 = new Vector2(v2.X + lu, v5.Y);
                Vector2 p7_1 = fun.Polar(v1, pi / 2, dmm / 2.0);
                Vector2 p7_2 = fun.Polar(p7_1, 0, oal);
                Vector2 v7;
                if (v6.Y == dmm / 2.0)
                {
                    v7 = v6;
                }
                else if (v6.Y < dmm / 2.0)
                {
                    v7 = fun.Inters(p7_1, p7_2, v6, fun.Polar(v6, pi / 4, oal));
                }
                else
                {
                    v7 = fun.Inters(p7_1, p7_2, v6, fun.Polar(v6, pi / -4, oal));
                }
                //Vector2 v7 = new Vector2((dmm - dn) / 2.00 / Math.Tan(ta) + v6.X, dmm / 2.00);
                Vector2 v8 = new Vector2(v2.X + oal - 0.15 * dmm, ds / 2);
                Vector2 v9 = new Vector2(v2.X + oal, 0.35 * dmm);
                Vector2 v10 = new Vector2(v9.X, -v9.Y);
                Vector2 v11 = new Vector2(v8.X, -v8.Y);
                Vector2 v12 = new Vector2(v7.X, -v7.Y);
                Vector2 v13 = new Vector2(v6.X, -v6.Y);
                Vector2 v14 = new Vector2(v5.X, -v5.Y);
                Vector2 v15 = new Vector2(v4.X, -v4.Y);
                Vector2 v16 = new Vector2(v3.X, -v3.Y);
                Vector2 v17 = new Vector2(v2.X, -v2.Y);
                Vector2 v19 = new Vector2(v8.X - drvl, ds1);
                Vector2 v18 = fun.Inters(v7, v8, v19, fun.Polar(v19, pi / 2, 150));
                Vector2 v20 = new Vector2(v8.X, v19.Y);
                Vector2 v21 = new Vector2(v20.X, v18.Y);
                Vector2 v22 = new Vector2(v21.X - (v18.Y - v19.Y) / 2.00 * Math.Tan(60 * pi / 180), (v18.Y + v19.Y) / 2.00);
                Vector2 v23 = new Vector2(v18.X, -v18.Y);
                Vector2 v24 = new Vector2(v19.X, -v19.Y);
                Vector2 v25 = new Vector2(v20.X, -v20.Y);
                Vector2 v26 = new Vector2(v21.X, -v21.Y);
                Vector2 v27 = new Vector2(v22.X, -v22.Y);
                Vector2 v41 = new Vector2(v1.X - 2, v1.Y);
                Vector2 v42 = new Vector2(v9.X + 2, v1.Y);
                Vector2 v43 = new Vector2(2 * v1.X - v17.X, v2.Y);
                Vector2 v44 = new Vector2(2 * v1.X - v2.X, v17.Y);
                Vector2 v80 = new Vector2(v8.X - drvl - 1 * scale, v7.Y);
                Vector2 v81 = new Vector2(v80.X, -v80.Y);
                Vector2 v82 = new Vector2(v80.X, ds / 2.00);
                Vector2 v83 = new Vector2(v82.X, -v82.Y);
                //柄方
                Vector2 v45 = new Vector2(oal + oal / 15.00, v8.Y - (v20.Y - v25.Y) * Math.Cos(45 * pi / 180));
                Vector2 v46 = new Vector2(v45.X - (v20.Y - v25.Y) / 2.00, v45.Y + (v20.Y - v25.Y) / 2.00);
                Vector2 v47 = new Vector2(v45.X * 2 - v46.X, v46.Y);
                Vector2 v48 = new Vector2(v45.X + v45.Y, v1.Y);
                Vector2 v49 = new Vector2(v45.X + v46.Y, v48.Y + v47.X - v45.X);
                Vector2 v50 = new Vector2(v49.X, -v49.Y);
                Vector2 v51 = new Vector2(v45.X, -v45.Y);
                Vector2 v52 = new Vector2(v47.X, -v47.Y);
                Vector2 v53 = new Vector2(v46.X, -v46.Y);
                Vector2 v54 = new Vector2(v45.X * 2 - v48.X, v48.Y);
                Vector2 v55 = new Vector2(v45.X * 2 - v50.X, v50.Y);
                Vector2 v56 = new Vector2(v45.X * 2 - v49.X, v49.Y);
                Vector2 v57 = new Vector2(v45.X - ds / 2.00 - 2, 0);
                Vector2 v58 = new Vector2(v45.X + ds / 2.00 + 2, 0);
                Vector2 v59 = new Vector2(v45.X, ds / 2.00 + 2);
                Vector2 v60 = new Vector2(v59.X, -v59.Y);
                string tctr = Convert.ToString(data["tctr"]);
                if (!tctr.Equals("0"))
                {
                    Vector2 a1 = fun.Polar(v3, fun.CalAngle(v3, v4), fun.CalDistance(v3, v4) / 2);
                    Vector2 a2 = fun.Polar(a1, 45 * pi / 180, 15);
                    Vector2 a3 = fun.Polar(a1, 45 * pi / 180, 16);
                    Line line101 = new Line(a1, a2);
                    dxf.AddEntity(line101);
                    fun.text(dxf, a3, 2, "丝锥公差带:" + tctr + "");

                }
                //线段
                //主视图

                double dx = v2.X;
                if (tcpd < dn)
                {
                    dx = (v5.Y - oal * (td - tcpd) / 4 / tcl - tcpd / 2) * 2 * tcl / (td - tcpd);
                }
                Vector2 v35 = new Vector2(dx, v5.Y);
                Vector2 v36 = new Vector2(dx, v14.Y);
                Line line34 = new Line(v5, v35);
                line34.Lineweight = Lineweight.W25;
                line34.Layer = additionalline;
                dxf.AddEntity(line34);
                Line line35 = new Line(v14, v36);
                line35.Lineweight = Lineweight.W25;
                line35.Layer = additionalline;
                dxf.AddEntity(line35);

                Vector2[] Line1 = { v1, v2 };
                fun.drawBLine(dxf, Line1, 0.3, contour);
                Vector2[] Line2 = { v2, v3 };
                fun.drawBLine(dxf, Line2, 0.3, contour);
                Vector2[] Line3 = { v3, v4 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line4 = { v4, v5 };
                fun.drawBLine(dxf, Line4, 0.3, contour);
                Vector2[] Line5 = { v5, v6 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
                Vector2[] Line6 = { v6, v7 };
                fun.drawBLine(dxf, Line6, 0.3, contour);
                Vector2[] Line7 = { v7, v80 };
                fun.drawBLine(dxf, Line7, 0.3, contour);
                Vector2[] Line8 = { v8, v9 };
                fun.drawBLine(dxf, Line8, 0.3, contour);
                Vector2[] Line9 = { v9, v10 };
                fun.drawBLine(dxf, Line9, 0.3, contour);
                Vector2[] Line10 = { v10, v11 };
                fun.drawBLine(dxf, Line10, 0.3, contour);
                Vector2[] Line11 = { v81, v12 };
                fun.drawBLine(dxf, Line11, 0.3, contour);
                Vector2[] Line12 = { v12, v13 };
                fun.drawBLine(dxf, Line12, 0.3, contour);
                Vector2[] Line13 = { v13, v14 };
                fun.drawBLine(dxf, Line13, 0.3, contour);
                Vector2[] Line14 = { v14, v15 };
                fun.drawBLine(dxf, Line14, 0.3, contour);
                Vector2[] Line15 = { v15, v16 };
                fun.drawBLine(dxf, Line15, 0.3, contour);
                Vector2[] Line16 = { v16, v17 };
                fun.drawBLine(dxf, Line16, 0.3, contour);
                Vector2[] Line17 = { v17, v1 };
                fun.drawBLine(dxf, Line17, 0.3, contour);
                Vector2[] Line18 = { v2, v17 };
                fun.drawBLine(dxf, Line18, 0.3, contour);
                Vector2[] Line23 = { v6, v13 };
                fun.drawBLine(dxf, Line23, 0.3, contour);
                Vector2[] Line24 = { v7, v12 };
                fun.drawBLine(dxf, Line24, 0.3, contour);
                Vector2[] Line25 = { v8, v21 };
                fun.drawBLine(dxf, Line25, 0.3, contour);
                Vector2[] Line26 = { v20, v25 };
                fun.drawBLine(dxf, Line26, 0.3, contour);
                Vector2[] Line27 = { v26, v11 };
                fun.drawBLine(dxf, Line27, 0.3, contour);
                Vector2[] Line28 = { v21, v18 };
                fun.drawBLine(dxf, Line28, 0.3, contour);
                Vector2[] Line29 = { v18, v19 };
                fun.drawBLine(dxf, Line29, 0.3, contour);
                Vector2[] Line30 = { v19, v20 };
                fun.drawBLine(dxf, Line30, 0.3, contour);
                Vector2[] Line31 = { v25, v24 };
                fun.drawBLine(dxf, Line31, 0.3, contour);
                Vector2[] Line32 = { v24, v23 };
                fun.drawBLine(dxf, Line32, 0.3, contour);
                Vector2[] Line33 = { v23, v26 };
                fun.drawBLine(dxf, Line33, 0.3, contour);
                //Arc Arc1 = new Arc(v22, (v18.Y - v19.Y) / 2.00 / Math.Cos(60 * pi / 180), -30, 30);
                //Arc Arc2 = new Arc(v27, (v18.Y - v19.Y) / 2.00 / Math.Cos(60 * pi / 180), -30, 30);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(v21));
                Arc1.Vertexes.Add(new LwPolylineVertex(v20));
                Arc1.Vertexes[0].Bulge = -((v21.Y - v20.Y) / 2.00 / Math.Cos(60 * pi / 180) - v21.X + v22.X) / ((v21.Y - v20.Y) / 2.00);
                fun.PolyFill(dxf, Arc1, 0.3, contour);
                LwPolyline Arc2 = new LwPolyline();
                Arc2.Vertexes.Add(new LwPolylineVertex(v25));
                Arc2.Vertexes.Add(new LwPolylineVertex(v26));
                Arc2.Vertexes[0].Bulge = -((v21.Y - v20.Y) / 2.00 / Math.Cos(60 * pi / 180) - v21.X + v22.X) / ((v21.Y - v20.Y) / 2.00);
                fun.PolyFill(dxf, Arc2, 0.3, contour);
                LwPolyline Arc4 = new LwPolyline();
                Arc4.Vertexes.Add(new LwPolylineVertex(v18));
                Arc4.Vertexes.Add(new LwPolylineVertex(v19));
                Arc4.Vertexes[0].Bulge = 1 * scale / ((v18.Y - v19.Y) / 2.00);
                fun.PolyFill(dxf, Arc4, 0.3, contour);
                LwPolyline Arc5 = new LwPolyline();
                Arc5.Vertexes.Add(new LwPolylineVertex(v24));
                Arc5.Vertexes.Add(new LwPolylineVertex(v23));
                Arc5.Vertexes[0].Bulge = 1 * scale / ((v24.Y - v23.Y) / 2.00);
                fun.PolyFill(dxf, Arc5, 0.3, contour);
                Vector2[] Line38 = { v41, v42 };
                fun.drawPlinetype(dxf, Line38, 0.15, centre, Linetype.Center);
                Vector2[] Line39 = { v18, v20 };
                fun.drawBLine(dxf, Line39, 0.15, contour);
                Vector2[] Line40 = { v19, v21 };
                fun.drawBLine(dxf, Line40, 0.15, contour);
                Vector2[] Line41 = { v24, v26 };
                fun.drawBLine(dxf, Line41, 0.15, contour);
                Vector2[] Line42 = { v23, v25 };
                fun.drawBLine(dxf, Line42, 0.15, contour);
                Line Line43 = new Line(v1, v43);
                Line Line44 = new Line(v1, v44);
                Vector2[] Line55 = { v80, v81 };
                fun.drawBLine(dxf, Line55, 0.3, contour);
                Vector2[] Line56 = { v82, v8 };
                fun.drawBLine(dxf, Line56, 0.3, contour);
                Vector2[] Line57 = { v83, v11 };
                fun.drawBLine(dxf, Line57, 0.3, contour);
                //柄方
                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(v47));
                poly1.Vertexes.Add(new LwPolylineVertex(v49));
                poly1.Vertexes.Add(new LwPolylineVertex(v50));
                poly1.Vertexes[1].Bulge = -Math.Tan(pi / 8);
                poly1.Vertexes.Add(new LwPolylineVertex(v52));
                poly1.Vertexes[3].Bulge = -Math.Tan(pi / 8);
                poly1.Vertexes.Add(new LwPolylineVertex(v53));
                poly1.Vertexes.Add(new LwPolylineVertex(v55));
                poly1.Vertexes[5].Bulge = -Math.Tan(pi / 8);
                poly1.Vertexes.Add(new LwPolylineVertex(v56));
                poly1.Vertexes.Add(new LwPolylineVertex(v46));
                poly1.Vertexes[7].Bulge = -Math.Tan(pi / 8);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.3, contour);
                Line Line53 = new Line(v57, v58);
                Line Line54 = new Line(v59, v60);
                //主视图图层
                Line43.Layer = dimensioning;
                Line44.Layer = dimensioning;
                //柄方图层
                Line53.Layer = centre;
                Line54.Layer = centre;
                Line53.Linetype = Linetype.Center;
                Line54.Linetype = Linetype.Center;
                //主视图
                dxf.AddEntity(Line43);
                dxf.AddEntity(Line44);
                //柄方
                dxf.AddEntity(Line53);
                dxf.AddEntity(Line54);
                //标注样式
                //箭头样式
                DimensionStyle dimensionStyle = fun.CreateDimStyle();
                dimensionStyle.ArrowSize = 0.5 * (oal / 40);
                dimensionStyle.ExtLineExtend = 0.6 * (oal / 40);//标注延长线长度/2
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                double height = (2.5 * (oal / 40)) / 2.0;
                double arrowsize = 0.5 * (oal / 40);
                //文本样式
                dimensionStyle.TextHeight = (2.5 * (oal / 40)) / 4.0;
                double offset = 20 * (oal / 40);
                //线段尺寸标注
                //尺寸1
                /*Angular2LineDimension angdim1 = new Angular2LineDimension(new Line(v1, v43), new Line(v1, v44), offset, dimensionStyle);
                angdim1.UserText = "SIG = " + Math.Round(sig / (pi / 180), 2) + "°";
                dxf.AddEntity(angdim1);*/
                //fun.jdbz2(dxf, new Line(v1, v43), new Line(v1, v44), offset /2.0, height , arrowsize , 0.4, "SIG = " + Math.Round(sig / (pi / 180), 2) + "°", "", "");
                //尺寸2
                LinearDimension dim2 = new LinearDimension(new Line(v3, v16), -v3.X + v43.X - offset - 5, 270, dimensionStyle);
                dim2.UserText = "TD = " + Math.Round(lu / scale, 2);
                dxf.AddEntity(dim2);
                //尺寸3
                double toh = Convert.ToDouble(data["thltctrh"]);
                double tol = Convert.ToDouble(data["thltctrl"]);
                if (toh == 0 && tol == 0)
                {
                    LinearDimension dim3 = new LinearDimension(new Line(v17, v15), -offset * (2 / 3.0), 0, dimensionStyle);
                    dim3.UserText = "THL = " + Math.Round(thl / scale, 2);
                    dxf.AddEntity(dim3);
                }
                else
                {
                    fun.dimrot(dxf, v17, v15, 0, -offset * (2 / 3.0), height, arrowsize, 2.5, "THL = " + Math.Round(thl / scale, 2), toh + "", tol + "");
                }
                //尺寸4
                LinearDimension dim4 = new LinearDimension(new Line(v17, v13), (-offset - 5) / 3.0, 0, dimensionStyle);
                dim4.UserText = "LU = " + Math.Round(lu / scale, 2);
                dxf.AddEntity(dim4);
                //尺寸5
                double toh1 = Convert.ToDouble(data["oaltctrh"]);
                double tol1 = Convert.ToDouble(data["oaltctrl"]);
                string oaltctr = Convert.ToString(data["oaltctr"]);
                if (toh1 == 0 && tol1 == 0)
                {
                    if (oaltctr.Equals("0"))
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v17, v10), -offset, 0, dimensionStyle);
                        dim5.UserText = "OAL = " + Math.Round(oal / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    else
                    {
                        LinearDimension dim7 = new LinearDimension(new Line(v17, v10), -offset, 0, dimensionStyle);
                        dim7.UserText = "OAL = " + Math.Round(oal / scale, 2) + "  " + oaltctr;
                        dxf.AddEntity(dim7);
                    }
                }
                else
                {
                    fun.dimrot(dxf, v17, v10, 0, -offset, height, arrowsize, 2.5, "OAL = " + Math.Round(oal / scale, 2), toh1 + "", tol1 + "");
                }

                //尺寸6
                LinearDimension dim6 = new LinearDimension(new Line(v23, v26), (-offset - (v26.Y - v11.Y)) / 3.0, 0, dimensionStyle);
                dim6.UserText = "DRVL = " + Math.Round(drvl / scale, 2);
                dxf.AddEntity(dim6);
                //尺寸7
                string tcdconws = Convert.ToString(data["tcdconws"]);
                if (tcdconws.Equals("0"))
                {
                    LinearDimension dim7 = new LinearDimension(new Line(v80, v81), (v9.X - v80.X + offset) / 2.0, 270, dimensionStyle);
                    dim7.UserText = "DMM = " + Math.Round(dmm / scale, 2);
                    dxf.AddEntity(dim7);
                }
                else
                {
                    LinearDimension dim7 = new LinearDimension(new Line(v80, v81), (v9.X - v80.X + offset) / 2.0, 270, dimensionStyle);
                    dim7.UserText = "DMM = " + Math.Round(dmm / scale, 2) + "  " + tcdconws;
                    dxf.AddEntity(dim7);
                }

                //尺寸8
                LinearDimension dim8 = new LinearDimension(new Line(v46, v50), -offset / 2.0, 135, dimensionStyle);
                dim8.UserText = "DRVSC = " + Math.Round(drvsc / scale, 2);
                dxf.AddEntity(dim8);
                //填充柄方
                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v47));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v49));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v50));
                hatchpoly1.Vertexes[1].Bulge = -Math.Tan(pi / 8);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v52));
                hatchpoly1.Vertexes[3].Bulge = -Math.Tan(pi / 8);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v53));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v55));
                hatchpoly1.Vertexes[5].Bulge = -Math.Tan(pi / 8);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v56));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v46));
                hatchpoly1.Vertexes[7].Bulge = -Math.Tan(pi / 8);
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 89, 2.5 * (td / 3.0), hline1, harc1, hatching);
                /* //填充螺旋槽
                 LwPolyline hatchpoly2 = new LwPolyline();
                 hatchpoly2.Vertexes.Add(new LwPolylineVertex(v2));
                 hatchpoly2.Vertexes.Add(new LwPolylineVertex(v3));
                 hatchpoly2.Vertexes.Add(new LwPolylineVertex(v4));
                 hatchpoly2.Vertexes.Add(new LwPolylineVertex(v5));
                 hatchpoly2.Vertexes.Add(new LwPolylineVertex(v6));
                 hatchpoly2.Vertexes.Add(new LwPolylineVertex(v13));
                 hatchpoly2.Vertexes.Add(new LwPolylineVertex(v14));
                 hatchpoly2.Vertexes.Add(new LwPolylineVertex(v15));
                 hatchpoly2.Vertexes.Add(new LwPolylineVertex(v16));
                 hatchpoly2.Vertexes.Add(new LwPolylineVertex(v17));
                 hatchpoly2.IsClosed = true;
                 String[] htype2 = new String[100];
                 Line[] hline2 = new Line[100];
                 int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                 for (int i = 0; i < hnumst2; i++)
                 {
                     htype2[i] = hatchpoly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                     if (htype2[i] == "Line")
                     {
                         hline2[i] = (Line)hatchpoly2.Explode()[i];
                     }
                 }
                 var x = lu / 5.00 * Math.Tan(FHA * pi / 180);
                 if (x < tcpd / 2.00)
                 {
                     fun.hatchsuboflinew(dxf, htype2, hnumst2, -FHA, lu / 2.00 * 8 * Math.Sin(FHA * pi / 180), hline2, contour, 0.3);
                 }
                 else
                 {
                     fun.hatchsuboflinew(dxf, htype2, hnumst2, -FHA, lu / 5.00 * 8 * Math.Sin(FHA * pi / 180), hline2, contour, 0.3);
                 }*/


                double lxxx = Convert.ToDouble(data["lxxx"]);
                if (lxxx == 0)
                {
                    Vector2 v01 = fun.Polar(v17, 90 * pi / 180, tcpd / 4);
                    Vector2 v02p = fun.Polar(v01, -FHA * pi / 180, 10);
                    Vector2 v02 = fun.Inters(v01, v02p, v15, v16);
                    Vector2 v03 = fun.Polar(v17, 90 * pi / 180, tcpd / 6 * 4);
                    Vector2 v04p = fun.Polar(v03, -FHA * pi / 180, 10);
                    Vector2 v04;
                    if (FHA <= 90 - Math.Atan((v15.X - v2.X) / (v03.Y - v15.Y)) * 180 / pi)
                    {
                        v04 = fun.Inters(v03, v04p, v4, v15);
                    }
                    else
                    {
                        v04 = fun.Inters(v03, v04p, v15, v16);
                    }

                    Vector2 v05 = new Vector2(v2.X, v2.Y);
                    Vector2 v06p = fun.Polar(v05, -FHA * pi / 180, 10);
                    Vector2 v06;
                    if (FHA <= 90 - Math.Atan((v15.X - v2.X) / (v05.Y - v15.Y)) * 180 / pi)
                    {
                        v06 = fun.Inters(v05, v06p, v4, v15);
                    }
                    else
                    {
                        v06 = fun.Inters(v05, v06p, v15, v16);
                    }
                    Vector2 v07p = fun.Polar(v05, 90 * pi / 180, (v03.Y - v01.Y));
                    Vector2 v08p = fun.Polar(v07p, -FHA * pi / 180, 10);
                    Vector2 v07 = fun.Inters(v07p, v08p, v3, v4);
                    Vector2 v08;
                    if (FHA <= 90 - Math.Atan((v15.X - v07.X) / (v07.Y - v15.Y)) * 180 / pi)
                    {
                        v08 = fun.Inters(v07, v08p, v4, v15);
                    }
                    else
                    {
                        v08 = fun.Inters(v07, v08p, v15, v16);
                    }




                    Vector2[] Line01 = { v4, v15 };
                    fun.drawBLine(dxf, Line01, 0.3, contour);
                    Line line01 = new Line(v01, v02);
                    line01.Lineweight = Lineweight.W25;
                    line01.Layer = additionalline;
                    dxf.AddEntity(line01);
                    Line line02 = new Line(v03, v04);
                    line02.Lineweight = Lineweight.W25;
                    line02.Layer = additionalline;
                    dxf.AddEntity(line02);
                    Line line03 = new Line(v05, v06);
                    line03.Lineweight = Lineweight.W25;
                    line03.Layer = additionalline;
                    dxf.AddEntity(line03);
                    Line line04 = new Line(v07, v08);
                    line04.Lineweight = Lineweight.W25;
                    line04.Layer = additionalline;
                    dxf.AddEntity(line04);


                    LwPolyline hatchpoly01 = new LwPolyline();
                    hatchpoly01.Vertexes.Add(new LwPolylineVertex(v01));
                    hatchpoly01.Vertexes.Add(new LwPolylineVertex(v17));
                    hatchpoly01.Vertexes.Add(new LwPolylineVertex(v16));
                    hatchpoly01.Vertexes.Add(new LwPolylineVertex(v02));
                    hatchpoly01.Vertexes.Add(new LwPolylineVertex(v01));
                    hatchpoly01.IsClosed = true;
                    String[] htype01 = new String[100];
                    Line[] hline01 = new Line[100];
                    Arc[] harc01 = new Arc[100];
                    int hnumst01 = hatchpoly01.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst01; i++)
                    {
                        htype01[i] = hatchpoly01.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                        if (htype01[i] == "Line")
                        {
                            hline01[i] = (Line)hatchpoly01.Explode()[i];
                        }
                        if (htype01[i] == "Arc")
                        {
                            harc01[i] = (Arc)hatchpoly01.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype01, hnumst01, 89, 2.5 * (td / 3.0), hline01, harc01, hatching);





                    LwPolyline hatchpoly02 = new LwPolyline();
                    hatchpoly02.Vertexes.Add(new LwPolylineVertex(v03));
                    hatchpoly02.Vertexes.Add(new LwPolylineVertex(v04));
                    hatchpoly02.Vertexes.Add(new LwPolylineVertex(v15));
                    hatchpoly02.Vertexes.Add(new LwPolylineVertex(v06));
                    hatchpoly02.Vertexes.Add(new LwPolylineVertex(v05));
                    hatchpoly02.Vertexes.Add(new LwPolylineVertex(v03));
                    hatchpoly02.IsClosed = true;
                    String[] htype02 = new String[102];
                    Line[] hline02 = new Line[102];
                    Arc[] harc02 = new Arc[102];
                    int hnumst02 = hatchpoly02.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst02; i++)
                    {
                        htype02[i] = hatchpoly02.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                        if (htype02[i] == "Line")
                        {
                            hline02[i] = (Line)hatchpoly02.Explode()[i];
                        }
                        if (htype02[i] == "Arc")
                        {
                            harc02[i] = (Arc)hatchpoly02.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype02, hnumst02, 89, 2.5 * (td / 3.0), hline02, harc02, hatching);


                    LwPolyline hatchpoly03 = new LwPolyline();
                    hatchpoly03.Vertexes.Add(new LwPolylineVertex(v07));
                    hatchpoly03.Vertexes.Add(new LwPolylineVertex(v08));
                    hatchpoly03.Vertexes.Add(new LwPolylineVertex(v15));
                    hatchpoly03.Vertexes.Add(new LwPolylineVertex(v4));
                    hatchpoly03.Vertexes.Add(new LwPolylineVertex(v07));
                    hatchpoly03.IsClosed = true;
                    String[] htype03 = new String[103];
                    Line[] hline03 = new Line[103];
                    Arc[] harc03 = new Arc[103];
                    int hnumst03 = hatchpoly03.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst03; i++)
                    {
                        htype03[i] = hatchpoly03.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                        if (htype03[i] == "Line")
                        {
                            hline03[i] = (Line)hatchpoly03.Explode()[i];
                        }
                        if (htype03[i] == "Arc")
                        {
                            harc03[i] = (Arc)hatchpoly03.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype03, hnumst03, 89, 2.5 * (td / 3.0), hline03, harc03, hatching);

                    Angular2LineDimension angdim2 = new Angular2LineDimension(new Line(v05, v06), new Line(v41, v42), offset * 5, dimensionStyle);
                    angdim2.UserText = "FHA = " + FHA + "°";
                    dxf.AddEntity(angdim2);

                    //fun.jdbz2(dxf, new Line(v41, v42), new Line(v05, v06), offset * 5, 2.5, 0.8, 0.4, "FHA = " + FHA + "°", "", "");


                }
                else
                {
                    Vector2 v01 = fun.Polar(v17, 90 * pi / 180, tcpd / 4);
                    Vector2 v02p = fun.Polar(v01, -FHA * pi / 180, 10);
                    Vector2 v02 = fun.Inters(v01, v02p, v15, v16);
                    Vector2 v03 = fun.Polar(v17, 90 * pi / 180, tcpd / 6 * 4);
                    Vector2 v04p = fun.Polar(v03, -FHA * pi / 180, 10);
                    Vector2 v04;
                    if (FHA <= 90 - Math.Atan((v15.X - v2.X) / (v03.Y - v15.Y)) * 180 / pi)
                    {
                        v04 = fun.Inters(v03, v04p, v4, v15);
                    }
                    else
                    {
                        v04 = fun.Inters(v03, v04p, v15, v16);
                    }

                    Vector2 v05 = new Vector2(v2.X, v2.Y);
                    Vector2 v06p = fun.Polar(v05, -FHA * pi / 180, 10);
                    Vector2 v06;
                    if (FHA <= 90 - Math.Atan((v15.X - v2.X) / (v05.Y - v15.Y)) * 180 / pi)
                    {
                        v06 = fun.Inters(v05, v06p, v4, v15);
                    }
                    else
                    {
                        v06 = fun.Inters(v05, v06p, v15, v16);
                    }
                    Vector2 v07p = fun.Polar(v05, 90 * pi / 180, (v03.Y - v01.Y));
                    Vector2 v08p = fun.Polar(v07p, -FHA * pi / 180, 10);
                    Vector2 v07 = fun.Inters(v07p, v08p, v3, v4);
                    Vector2 v08;
                    if (FHA <= 90 - Math.Atan((v15.X - v07.X) / (v07.Y - v15.Y)) * 180 / pi)
                    {
                        v08 = fun.Inters(v07, v08p, v4, v15);
                    }
                    else
                    {
                        v08 = fun.Inters(v07, v08p, v15, v16);
                    }

                    Vector2 a1 = new Vector2(v01.X, -v01.Y);
                    Vector2 a2 = new Vector2(v02.X, -v02.Y);
                    Vector2 a3 = new Vector2(v03.X, -v03.Y);
                    Vector2 a4 = new Vector2(v04.X, -v04.Y);
                    Vector2 a5 = new Vector2(v05.X, -v05.Y);
                    Vector2 a6 = new Vector2(v06.X, -v06.Y);
                    Vector2 a7 = new Vector2(v07.X, -v07.Y);
                    Vector2 a8 = new Vector2(v08.X, -v08.Y);



                    Vector2[] Line01 = { v4, v15 };
                    fun.drawBLine(dxf, Line01, 0.3, contour);
                    Line line01 = new Line(a1, a2);
                    line01.Lineweight = Lineweight.W25;
                    line01.Layer = additionalline;
                    dxf.AddEntity(line01);
                    Line line02 = new Line(a3, a4);
                    line02.Lineweight = Lineweight.W25;
                    line02.Layer = additionalline;
                    dxf.AddEntity(line02);
                    Line line03 = new Line(a5, a6);
                    line03.Lineweight = Lineweight.W25;
                    line03.Layer = additionalline;
                    dxf.AddEntity(line03);
                    Line line04 = new Line(a7, a8);
                    line04.Lineweight = Lineweight.W25;
                    line04.Layer = additionalline;
                    dxf.AddEntity(line04);

                    LwPolyline hatchpoly01 = new LwPolyline();
                    hatchpoly01.Vertexes.Add(new LwPolylineVertex(a1));
                    hatchpoly01.Vertexes.Add(new LwPolylineVertex(v2));
                    hatchpoly01.Vertexes.Add(new LwPolylineVertex(v3));
                    hatchpoly01.Vertexes.Add(new LwPolylineVertex(a2));
                    hatchpoly01.Vertexes.Add(new LwPolylineVertex(a1));
                    hatchpoly01.IsClosed = true;
                    String[] htype01 = new String[100];
                    Line[] hline01 = new Line[100];
                    Arc[] harc01 = new Arc[100];
                    int hnumst01 = hatchpoly01.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst01; i++)
                    {
                        htype01[i] = hatchpoly01.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                        if (htype01[i] == "Line")
                        {
                            hline01[i] = (Line)hatchpoly01.Explode()[i];
                        }
                        if (htype01[i] == "Arc")
                        {
                            harc01[i] = (Arc)hatchpoly01.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype01, hnumst01, 89, 2.5 * (td / 3.0), hline01, harc01, hatching);


                    LwPolyline hatchpoly02 = new LwPolyline();
                    hatchpoly02.Vertexes.Add(new LwPolylineVertex(a3));
                    hatchpoly02.Vertexes.Add(new LwPolylineVertex(a4));
                    hatchpoly02.Vertexes.Add(new LwPolylineVertex(v4));
                    hatchpoly02.Vertexes.Add(new LwPolylineVertex(a6));
                    hatchpoly02.Vertexes.Add(new LwPolylineVertex(a5));
                    hatchpoly02.Vertexes.Add(new LwPolylineVertex(a3));
                    hatchpoly02.IsClosed = true;
                    String[] htype02 = new String[102];
                    Line[] hline02 = new Line[102];
                    Arc[] harc02 = new Arc[102];
                    int hnumst02 = hatchpoly02.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst02; i++)
                    {
                        htype02[i] = hatchpoly02.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                        if (htype02[i] == "Line")
                        {
                            hline02[i] = (Line)hatchpoly02.Explode()[i];
                        }
                        if (htype02[i] == "Arc")
                        {
                            harc02[i] = (Arc)hatchpoly02.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype02, hnumst02, 89, 2.5 * (td / 3.0), hline02, harc02, hatching);


                    LwPolyline hatchpoly03 = new LwPolyline();
                    hatchpoly03.Vertexes.Add(new LwPolylineVertex(a7));
                    hatchpoly03.Vertexes.Add(new LwPolylineVertex(a8));
                    hatchpoly03.Vertexes.Add(new LwPolylineVertex(v4));
                    hatchpoly03.Vertexes.Add(new LwPolylineVertex(v15));
                    hatchpoly03.Vertexes.Add(new LwPolylineVertex(a7));
                    hatchpoly03.IsClosed = true;
                    String[] htype03 = new String[103];
                    Line[] hline03 = new Line[103];
                    Arc[] harc03 = new Arc[103];
                    int hnumst03 = hatchpoly03.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst03; i++)
                    {
                        htype03[i] = hatchpoly03.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                        if (htype03[i] == "Line")
                        {
                            hline03[i] = (Line)hatchpoly03.Explode()[i];
                        }
                        if (htype03[i] == "Arc")
                        {
                            harc03[i] = (Arc)hatchpoly03.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype03, hnumst03, 89, 2.5 * (td / 3.0), hline03, harc03, hatching);

                    Angular2LineDimension angdim2 = new Angular2LineDimension(new Line(a5, a6), new Line(v41, v42), offset * 5, dimensionStyle);
                    angdim2.UserText = "FHA = " + FHA + "°";
                    dxf.AddEntity(angdim2);

                    //fun.jdbz2(dxf, new Line(v41, v42), new Line(a5, a6),  offset * 5, 2.5, 0.8, 0.4, "FHA = " + FHA + "°", "", "");

                }

                string l5;
                string kr;

                if (mc == 0) { l5 = "8P"; kr = "4°30′"; }
                else if (mc == 1) { l5 = "4P"; kr = "8°30′"; }
                else if (mc == 2) { l5 = "2P"; kr = "17°"; }
                else if (mc == 3) { l5 = "6P"; kr = "6°"; }
                else { l5 = ""; kr = ""; }

                if (mc == 3 && tp > 2.5)
                {
                    Line line01 = new Line(fun.Polar(v80, pi, 4), fun.Polar(v81, pi, 4)); fun.drawBline(dxf, line01, 0.3, contour);
                }
                if (mc == 1 && tp > 2.5)
                {
                    Line line01 = new Line(fun.Polar(v80, pi, 4), fun.Polar(v81, pi, 4)); fun.drawBline(dxf, line01, 0.3, contour);
                    Line line02 = new Line(fun.Polar(v80, pi, 6.5), fun.Polar(v81, pi, 6.5)); fun.drawBline(dxf, line02, 0.3, contour);
                }


              /*  LinearDimension dim00 = new LinearDimension(new Line(v3, v2), offset, 0, dimensionStyle);
                dim00.UserText = "TCL = " + l5;
                dxf.AddEntity(dim00);*/

             //   fun.jdbz2(dxf, new Line(v3, v4), new Line(v2, v3), offset, 2.5, 2, 0.6, "KAPR=" + kr, "", "");
                //图框
                if (isframe == 1)
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(v1.X - 210 + (v45.X + v8.Y - v1.X) / 2.00, v1.Y + 148.5), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }
            if (fdc == 2)
            {
                double soal = Convert.ToDouble(data["oal"]);
                double scale = Convert.ToDouble(data["scale"]); //放大系数
                if (scale == 0 && soal < 105)
                {
                    scale = 2.0;
                }
                else if (scale == 0 && soal < 210)
                {
                    scale = 1.0;
                }
                else if (scale == 0)
                {
                    scale = 0.5;
                }
                double pi = Math.PI;
                double td = Convert.ToDouble(data["td"]) * scale;
                double dmm = Convert.ToDouble(data["dmm"]) * scale;
                double tp = Convert.ToDouble(data["tp"]) * scale;
                double dn = Convert.ToDouble(data["dn"]) * scale;
                if (dn == 0)
                {
                    dn = td - 1.1325 * tp - 0.15;
                }
                double mc = Convert.ToDouble(data["mc"]);
                double qxzj;
                if (mc == 0)
                {
                    qxzj = 4.5 * pi / 180;
                }
                if (mc == 1)
                {
                    qxzj = 8.5 * pi / 180;
                }
                if (mc == 2)
                {
                    qxzj = 17 * pi / 180;
                }
                else
                {
                    qxzj = 6 * pi / 180;
                }

                double tcl;
                if (mc == 0)
                {
                    tcl = 8 * tp;
                }
                else if (mc == 1)
                {
                    tcl = 4 * tp;
                }
                else if (mc == 2)
                {
                    tcl = 2 * tp;
                }
                else
                {
                    tcl = 6 * tp;
                }

                if (tcl == 0)
                {
                    tcl = tp * 2.3;
                }
                double tcpd = td - tcl * Math.Tan(qxzj);
                double thl = Convert.ToDouble(data["thl"]) * scale;
                double lu = Convert.ToDouble(data["lu"]) * scale;
                if (lu == 0)
                {
                    lu = thl * 39 / 22;
                }
                double oal = Convert.ToDouble(data["oal"]) * scale;
                double drvsc = Convert.ToDouble(data["drvsc"]) * scale;
                double drvl = Convert.ToDouble(data["drvl"]) * scale;
                double sig = Convert.ToDouble(data["sig"]) * pi / 180;
                double ta = Convert.ToDouble(data["ta"]) * pi / 180;
                double ds = dmm - 0.08 * scale;//柄方外圆
                double ds1 = dmm * 1 / 10.0;
                double isframe = Convert.ToDouble(data["isframe"]);
                //坐标
                //主视图
                Vector2 v2 = new Vector2(-oal / 2.00, tcpd / 2.00);
                Vector2 v1 = new Vector2(v2.X - v2.Y / Math.Tan(sig / 2.00), 0);
                Vector2 v3 = new Vector2(v2.X + tcl, td / 2.00);
                Vector2 v4 = new Vector2(v2.X + thl, v3.Y);
                Vector2 v5 = new Vector2((td - dn) / 2.00 + v4.X, dn / 2.00);
                Vector2 v6 = new Vector2(v2.X + lu, v5.Y);
                Vector2 p7_1 = fun.Polar(v1, pi / 2, dmm / 2.0);
                Vector2 p7_2 = fun.Polar(p7_1, 0, oal);
                Vector2 v7;
                if (v6.Y == dmm / 2.0)
                {
                    v7 = v6;
                }
                else if (v6.Y < dmm / 2.0)
                {
                    v7 = fun.Inters(p7_1, p7_2, v6, fun.Polar(v6, pi / 4, oal));
                }
                else
                {
                    v7 = fun.Inters(p7_1, p7_2, v6, fun.Polar(v6, pi / -4, oal));
                }
                //Vector2 v7 = new Vector2((dmm - dn) / 2.00 / Math.Tan(ta) + v6.X, dmm / 2.00);
                Vector2 v8 = new Vector2(v2.X + oal - 0.15 * dmm, ds / 2);
                Vector2 v9 = new Vector2(v2.X + oal, 0.35 * dmm);
                Vector2 v10 = new Vector2(v9.X, -v9.Y);
                Vector2 v11 = new Vector2(v8.X, -v8.Y);
                Vector2 v12 = new Vector2(v7.X, -v7.Y);
                Vector2 v13 = new Vector2(v6.X, -v6.Y);
                Vector2 v14 = new Vector2(v5.X, -v5.Y);
                Vector2 v15 = new Vector2(v4.X, -v4.Y);
                Vector2 v16 = new Vector2(v3.X, -v3.Y);
                Vector2 v17 = new Vector2(v2.X, -v2.Y);
                Vector2 v19 = new Vector2(v8.X - drvl, ds1);
                Vector2 v18 = fun.Inters(v7, v8, v19, fun.Polar(v19, pi / 2, 150));
                Vector2 v20 = new Vector2(v8.X, v19.Y);
                Vector2 v21 = new Vector2(v20.X, v18.Y);
                Vector2 v22 = new Vector2(v21.X - (v18.Y - v19.Y) / 2.00 * Math.Tan(60 * pi / 180), (v18.Y + v19.Y) / 2.00);
                Vector2 v23 = new Vector2(v18.X, -v18.Y);
                Vector2 v24 = new Vector2(v19.X, -v19.Y);
                Vector2 v25 = new Vector2(v20.X, -v20.Y);
                Vector2 v26 = new Vector2(v21.X, -v21.Y);
                Vector2 v27 = new Vector2(v22.X, -v22.Y);
                Vector2 v41 = new Vector2(v1.X - 2, v1.Y);
                Vector2 v42 = new Vector2(v9.X + 2, v1.Y);
                Vector2 v43 = new Vector2(2 * v1.X - v17.X, v2.Y);
                Vector2 v44 = new Vector2(2 * v1.X - v2.X, v17.Y);
                //Vector2 v61 = new Vector2(Math.Sqrt(tp * tp * 49 - (v2.Y-v33.Y)* (v2.Y - v33.Y))+v2.X, wcf * 5 / 4.00);
                //Vector2 v63 = new Vector2(v61.X, v33.Y*2-v61.Y);
                //Vector2 v64 = new Vector2(v61.X - (v61.Y - v33.Y) / ((v61.X - v3.X) / (v3.Y - v61.Y)), v33.Y);
                //Vector2 v62 = new Vector2(v64.X + Math.Sqrt((v61.X - v64.X) * (v61.X - v64.X) + (v61.Y - v33.Y) * (v61.Y - v33.Y)), wcf / 2.00);
                Vector2 v80 = new Vector2(v8.X - drvl - 1 * scale, v7.Y);
                Vector2 v81 = new Vector2(v80.X, -v80.Y);
                Vector2 v82 = new Vector2(v80.X, ds / 2.00);
                Vector2 v83 = new Vector2(v82.X, -v82.Y);
                //螺尖槽
                Vector2 v87 = new Vector2(v2.X + tcpd * 5 / 36, v2.Y);
                Vector2 v88 = new Vector2(v2.X + tcl + thl / 5, v87.Y - 5 * tcpd / 18);
                Vector2 v86 = new Vector2(v87.X, v87.Y - 5 * tcpd / 9);
                Vector2 v89 = new Vector2(v87.X, v87.Y + (v87.X - v2.X) * (td - tcpd) / 2 / tcl);
                Vector2 v84 = new Vector2(v87.X, -v89.Y);
                Vector2 v85 = new Vector2(v86.X + (-v88.Y - v84.Y) * (td - tcpd) / 2 / tcl, -v88.Y);
                Vector2 v90 = new Vector2((v87.X - v88.X) * v88.Y * v88.Y / (v87.Y - v88.Y) / (v87.Y - v88.Y) + v88.X, 0);
                Vector2 v91 = new Vector2(v90.X, v88.Y * 2 - v90.Y);
                Vector2 v93 = new Vector2(v88.X, v15.Y);
                double cl = Math.Sqrt((v85.Y - v84.Y) * (v85.Y - v84.Y) + (v85.X - v84.X) * (v85.X - v84.X)) / 2;
                double sr = Math.Sqrt(cl * cl + (cl * (td - tcpd) / 2 / tcl) * (cl * (td - tcpd) / 2 / tcl));
                double h = sr - (td - tcpd) * cl / 2 / tcl;
                Vector2 v94 = new Vector2(v85.X, v85.Y - sr);
                Vector2 v92 = new Vector2(v87.X, Math.Sqrt(sr * sr - (v85.X - v86.X) * (v85.X - v86.X)) + v94.Y);
                //排屑槽
                Vector2 v95 = new Vector2(v2.X + lu - 3, v88.Y);
                double cr = (v5.Y - v88.Y) * 2;
                Vector2 v96 = new Vector2(v95.X - cr * Math.Sin(60 * pi / 180), v5.Y);
                Vector2 v97 = new Vector2(v95.X, -v95.Y);
                Vector2 v98 = new Vector2(v96.X, -v96.Y);
                //柄方
                Vector2 v45 = new Vector2(oal + oal / 15.00, v8.Y - (v20.Y - v25.Y) * Math.Cos(45 * pi / 180));
                Vector2 v46 = new Vector2(v45.X - (v20.Y - v25.Y) / 2.00, v45.Y + (v20.Y - v25.Y) / 2.00);
                Vector2 v47 = new Vector2(v45.X * 2 - v46.X, v46.Y);
                Vector2 v48 = new Vector2(v45.X + v45.Y, v1.Y);
                Vector2 v49 = new Vector2(v45.X + v46.Y, v48.Y + v47.X - v45.X);
                Vector2 v50 = new Vector2(v49.X, -v49.Y);
                Vector2 v51 = new Vector2(v45.X, -v45.Y);
                Vector2 v52 = new Vector2(v47.X, -v47.Y);
                Vector2 v53 = new Vector2(v46.X, -v46.Y);
                Vector2 v54 = new Vector2(v45.X * 2 - v48.X, v48.Y);
                Vector2 v55 = new Vector2(v45.X * 2 - v50.X, v50.Y);
                Vector2 v56 = new Vector2(v45.X * 2 - v49.X, v49.Y);
                Vector2 v57 = new Vector2(v45.X - ds / 2.00 - 2, 0);
                Vector2 v58 = new Vector2(v45.X + ds / 2.00 + 2, 0);
                Vector2 v59 = new Vector2(v45.X, ds / 2.00 + 2);
                Vector2 v60 = new Vector2(v59.X, -v59.Y);
                string tctr = Convert.ToString(data["tctr"]);
                if (!tctr.Equals("0"))
                {
                    Vector2 a1 = fun.Polar(v3, fun.CalAngle(v3, v4), fun.CalDistance(v3, v4) / 2);
                    Vector2 a2 = fun.Polar(a1, 45 * pi / 180, 15);
                    Vector2 a3 = fun.Polar(a1, 45 * pi / 180, 16);
                    Line line101 = new Line(a1, a2);
                    dxf.AddEntity(line101);
                    fun.text(dxf, a3, 2, "丝锥公差带:" + tctr + "");

                }
                //线段
                double dx = v2.X;
                if (tcpd < dn)
                {
                    dx = (v5.Y - oal * (td - tcpd) / 4 / tcl - tcpd / 2) * 2 * tcl / (td - tcpd);
                }
                Vector2 v35 = new Vector2(dx, v5.Y);
                Vector2 v36 = new Vector2(dx, v14.Y);
                Line line34 = new Line(v5, v35);
                line34.Lineweight = Lineweight.W25;
                line34.Layer = additionalline;
                dxf.AddEntity(line34);
                Line line35 = new Line(v14, v36);
                line35.Lineweight = Lineweight.W25;
                line35.Layer = additionalline;
                dxf.AddEntity(line35);
                //主视图
                Vector2[] Line1 = { v1, v2 };
                fun.drawBLine(dxf, Line1, 0.3, contour);
                Vector2[] Line2 = { v2, v3 };
                fun.drawBLine(dxf, Line2, 0.3, contour);
                Vector2[] Line3 = { v3, v4 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line4 = { v4, v5 };
                fun.drawBLine(dxf, Line4, 0.3, contour);
                Vector2[] Line5 = { v5, v6 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
                Vector2[] Line6 = { v6, v7 };
                fun.drawBLine(dxf, Line6, 0.3, contour);
                Vector2[] Line7 = { v7, v80 };
                fun.drawBLine(dxf, Line7, 0.3, contour);
                Vector2[] Line8 = { v8, v9 };
                fun.drawBLine(dxf, Line8, 0.3, contour);
                Vector2[] Line9 = { v9, v10 };
                fun.drawBLine(dxf, Line9, 0.3, contour);
                Vector2[] Line10 = { v10, v11 };
                fun.drawBLine(dxf, Line10, 0.3, contour);
                Vector2[] Line11 = { v81, v12 };
                fun.drawBLine(dxf, Line11, 0.3, contour);
                Vector2[] Line12 = { v12, v13 };
                fun.drawBLine(dxf, Line12, 0.3, contour);
                Vector2[] Line13 = { v13, v14 };
                fun.drawBLine(dxf, Line13, 0.3, contour);
                Vector2[] Line14 = { v14, v15 };
                fun.drawBLine(dxf, Line14, 0.3, contour);
                Vector2[] Line15 = { v15, v16 };
                fun.drawBLine(dxf, Line15, 0.3, contour);
                Vector2[] Line16 = { v16, v17 };
                fun.drawBLine(dxf, Line16, 0.3, contour);
                Vector2[] Line17 = { v17, v1 };
                fun.drawBLine(dxf, Line17, 0.3, contour);
                Vector2[] Line18 = { v2, v17 };
                fun.drawBLine(dxf, Line18, 0.3, contour);
                Vector2[] Line23 = { v6, v13 };
                fun.drawBLine(dxf, Line23, 0.3, contour);
                Vector2[] Line24 = { v7, v12 };
                fun.drawBLine(dxf, Line24, 0.3, contour);
                Vector2[] Line25 = { v8, v21 };
                fun.drawBLine(dxf, Line25, 0.3, contour);
                Vector2[] Line26 = { v20, v25 };
                fun.drawBLine(dxf, Line26, 0.3, contour);
                Vector2[] Line27 = { v26, v11 };
                fun.drawBLine(dxf, Line27, 0.3, contour);
                Vector2[] Line28 = { v21, v18 };
                fun.drawBLine(dxf, Line28, 0.3, contour);
                Vector2[] Line29 = { v18, v19 };
                fun.drawBLine(dxf, Line29, 0.3, contour);
                Vector2[] Line30 = { v19, v20 };
                fun.drawBLine(dxf, Line30, 0.3, contour);
                Vector2[] Line31 = { v25, v24 };
                fun.drawBLine(dxf, Line31, 0.3, contour);
                Vector2[] Line32 = { v24, v23 };
                fun.drawBLine(dxf, Line32, 0.3, contour);
                Vector2[] Line33 = { v23, v26 };
                fun.drawBLine(dxf, Line33, 0.3, contour);
                //Arc Arc1 = new Arc(v22, (v18.Y - v19.Y) / 2.00 / Math.Cos(60 * pi / 180), -30, 30);
                //Arc Arc2 = new Arc(v27, (v18.Y - v19.Y) / 2.00 / Math.Cos(60 * pi / 180), -30, 30);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(v21));
                Arc1.Vertexes.Add(new LwPolylineVertex(v20));
                Arc1.Vertexes[0].Bulge = -((v21.Y - v20.Y) / 2.00 / Math.Cos(60 * pi / 180) - v21.X + v22.X) / ((v21.Y - v20.Y) / 2.00);
                fun.PolyFill(dxf, Arc1, 0.3, contour);
                LwPolyline Arc2 = new LwPolyline();
                Arc2.Vertexes.Add(new LwPolylineVertex(v25));
                Arc2.Vertexes.Add(new LwPolylineVertex(v26));
                Arc2.Vertexes[0].Bulge = -((v21.Y - v20.Y) / 2.00 / Math.Cos(60 * pi / 180) - v21.X + v22.X) / ((v21.Y - v20.Y) / 2.00);
                fun.PolyFill(dxf, Arc2, 0.3, contour);
                LwPolyline Arc4 = new LwPolyline();
                Arc4.Vertexes.Add(new LwPolylineVertex(v18));
                Arc4.Vertexes.Add(new LwPolylineVertex(v19));
                Arc4.Vertexes[0].Bulge = 1 * scale / ((v18.Y - v19.Y) / 2.00);
                fun.PolyFill(dxf, Arc4, 0.3, contour);
                LwPolyline Arc5 = new LwPolyline();
                Arc5.Vertexes.Add(new LwPolylineVertex(v24));
                Arc5.Vertexes.Add(new LwPolylineVertex(v23));
                Arc5.Vertexes[0].Bulge = 1 * scale / ((v24.Y - v23.Y) / 2.00);
                fun.PolyFill(dxf, Arc5, 0.3, contour);
                Vector2[] Line38 = { v41, v42 };
                fun.drawPlinetype(dxf, Line38, 0.15, centre, Linetype.Center);
                Vector2[] Line39 = { v18, v20 };
                fun.drawBLine(dxf, Line39, 0.15, contour);
                Vector2[] Line40 = { v19, v21 };
                fun.drawBLine(dxf, Line40, 0.15, contour);
                Vector2[] Line41 = { v24, v26 };
                fun.drawBLine(dxf, Line41, 0.15, contour);
                Vector2[] Line42 = { v23, v25 };
                fun.drawBLine(dxf, Line42, 0.15, contour);
                Line Line43 = new Line(v1, v43);
                Line Line44 = new Line(v1, v44);
                Vector2[] Line55 = { v80, v81 };
                fun.drawBLine(dxf, Line55, 0.3, contour);
                Vector2[] Line56 = { v82, v8 };
                fun.drawBLine(dxf, Line56, 0.3, contour);
                Vector2[] Line57 = { v83, v11 };
                fun.drawBLine(dxf, Line57, 0.3, contour);
                Line Line58 = new Line(v89, v87);
                LwPolyline Arc3 = new LwPolyline();
                Arc3.Vertexes.Add(new LwPolylineVertex(v87));
                Arc3.Vertexes.Add(new LwPolylineVertex(v86));
                Arc3.Vertexes[0].Bulge = (v87.X - v2.X) / (v87.Y - v86.Y) * 2;
                //fun.PolyFill(dxf, Arc3, 0.1, contour);
                Arc3.Layer = contour;
                dxf.AddEntity(Arc3);
                List<Vector3> point1 = new List<Vector3>
            {
                fun.Tothree(v86),
                fun.Tothree(v90),
                fun.Tothree(v88),
                fun.Tothree(v91),
                fun.Tothree(v87),
            };
                Spline spline1 = new Spline(point1);
                spline1.Layer = contour;
                dxf.AddEntity(spline1);
                Line Line59 = new Line(v86, v92);
                LwPolyline Arc6 = new LwPolyline();
                Arc6.Vertexes.Add(new LwPolylineVertex(v85));
                Arc6.Vertexes.Add(new LwPolylineVertex(v84));
                Arc6.Vertexes[0].Bulge = h / cl;
                Arc6.Layer = contour;
                dxf.AddEntity(Arc6);
                Line Line60 = new Line(v85, v93);
                LwPolyline Arc7 = new LwPolyline();
                Arc7.Vertexes.Add(new LwPolylineVertex(v95));
                Arc7.Vertexes.Add(new LwPolylineVertex(v96));
                Arc7.Vertexes[0].Bulge = cr * (1 - Math.Sin(60 * pi / 180)) / (cr / 2);
                Arc7.Layer = contour;
                dxf.AddEntity(Arc7);
                Line Line61 = new Line(v88, v95);
                LwPolyline Arc8 = new LwPolyline();
                Arc8.Vertexes.Add(new LwPolylineVertex(v98));
                Arc8.Vertexes.Add(new LwPolylineVertex(v97));
                Arc8.Vertexes[0].Bulge = cr * (1 - Math.Sin(60 * pi / 180)) / (cr / 2);
                Arc8.Layer = contour;
                dxf.AddEntity(Arc8);
                Line Line62 = new Line(v85, v97);
                Vector2[] Line63 = { new Vector2(v4.X, v95.Y), new Vector2(v4.X, v97.Y) };
                fun.drawBLine(dxf, Line63, 0.3, contour);
                Vector2[] Line64 = { new Vector2(v5.X, v95.Y), new Vector2(v5.X, v97.Y) };
                fun.drawBLine(dxf, Line64, 0.3, contour);
                //柄方
                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(v47));
                poly1.Vertexes.Add(new LwPolylineVertex(v49));
                poly1.Vertexes.Add(new LwPolylineVertex(v50));
                poly1.Vertexes[1].Bulge = -Math.Tan(pi / 8);
                poly1.Vertexes.Add(new LwPolylineVertex(v52));
                poly1.Vertexes[3].Bulge = -Math.Tan(pi / 8);
                poly1.Vertexes.Add(new LwPolylineVertex(v53));
                poly1.Vertexes.Add(new LwPolylineVertex(v55));
                poly1.Vertexes[5].Bulge = -Math.Tan(pi / 8);
                poly1.Vertexes.Add(new LwPolylineVertex(v56));
                poly1.Vertexes.Add(new LwPolylineVertex(v46));
                poly1.Vertexes[7].Bulge = -Math.Tan(pi / 8);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.3, contour);
                Line Line53 = new Line(v57, v58);
                Line Line54 = new Line(v59, v60);
                //主视图图层
                Line43.Layer = dimensioning;
                Line44.Layer = dimensioning;
                Line58.Layer = contour;
                Line59.Layer = contour;
                Line60.Layer = contour;
                Line61.Layer = contour;
                Line62.Layer = contour;
                //柄方图层
                Line53.Layer = centre;
                Line54.Layer = centre;
                Line53.Linetype = Linetype.Center;
                Line54.Linetype = Linetype.Center;
                //主视图
                dxf.AddEntity(Line43);
                dxf.AddEntity(Line44);
                dxf.AddEntity(Line58);
                dxf.AddEntity(Line59);
                dxf.AddEntity(Line60);
                dxf.AddEntity(Line61);
                dxf.AddEntity(Line62);
                //柄方
                dxf.AddEntity(Line53);
                dxf.AddEntity(Line54);
                //标注样式
                //箭头样式
                DimensionStyle dimensionStyle = fun.CreateDimStyle();
                dimensionStyle.ArrowSize = 0.5 * (oal / 40);
                dimensionStyle.ExtLineExtend = 0.6 * (oal / 40);//标注延长线长度/2
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                double height = (2.5 * (oal / 40)) / 2.0;
                double arrowsize = 0.5 * (oal / 40);
                //文本样式
                dimensionStyle.TextHeight = (2.5 * (oal / 40)) / 4.0;
                double offset = 20 * (oal / 40);
                //线段尺寸标注
                //尺寸1
                /*
                Angular2LineDimension angdim1 = new Angular2LineDimension(new Line(v1, v43), new Line(v1, v44), offset, dimensionStyle);
                angdim1.UserText = "SIG = " + Math.Round(sig / (pi / 180), 2) + "°";
                dxf.AddEntity(angdim1);*/

                //  fun.jdbz2(dxf, new Line(v1, v43), new Line(v1, v44), offset /2.0, height , arrowsize , 0.4, "SIG = " + Math.Round(sig / (pi / 180), 2) + "°", "", "");
                //尺寸2
                LinearDimension dim2 = new LinearDimension(new Line(v3, v16), -v3.X + v43.X - offset - 5, 270, dimensionStyle);
                dim2.UserText = "TD = " + Math.Round(lu / scale, 2);
                dxf.AddEntity(dim2);
                //尺寸3
                double toh = Convert.ToDouble(data["thltctrh"]);
                double tol = Convert.ToDouble(data["thltctrl"]);
                if (toh == 0 && tol == 0)
                {
                    LinearDimension dim3 = new LinearDimension(new Line(v17, v15), -offset * (2 / 3.0), 0, dimensionStyle);
                    dim3.UserText = "THL = " + Math.Round(thl / scale, 2);
                    dxf.AddEntity(dim3);
                }
                else
                {
                    fun.dimrot(dxf, v17, v15, 0, -offset * (2 / 3.0), 2.5, 2, 2.5, "THL = " + Math.Round(thl / scale, 2), toh + "", tol + "");
                }
                //尺寸4
                LinearDimension dim4 = new LinearDimension(new Line(v17, v13), (-offset - 5) / 3.0, 0, dimensionStyle);
                dim4.UserText = "LU = " + Math.Round(lu / scale, 2);
                dxf.AddEntity(dim4);
                //尺寸5
                double toh1 = Convert.ToDouble(data["oaltctrh"]);
                double tol1 = Convert.ToDouble(data["oaltctrl"]);
                string oaltctr = Convert.ToString(data["oaltctr"]);
                if (toh1 == 0 && tol1 == 0)
                {
                    if (oaltctr.Equals("0"))
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v17, v10), -offset, 0, dimensionStyle);
                        dim5.UserText = "OAL = " + Math.Round(oal / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    else
                    {
                        LinearDimension dim7 = new LinearDimension(new Line(v17, v10), -offset, 0, dimensionStyle);
                        dim7.UserText = "OAL = " + Math.Round(oal / scale, 2) + "  " + oaltctr;
                        dxf.AddEntity(dim7);
                    }
                }
                else
                {
                    fun.dimrot(dxf, v17, v10, 0, -offset * 2, height, arrowsize, 2.5, "OAL = " + Math.Round(oal / scale, 2), toh1 + "", tol1 + "");
                }
                //尺寸6
                LinearDimension dim6 = new LinearDimension(new Line(v23, v26), (-offset - (v26.Y - v11.Y)) / 3.0, 0, dimensionStyle);
                dim6.UserText = "DRVL = " + Math.Round(drvl / scale, 2);
                dxf.AddEntity(dim6);
                //尺寸7
                string tcdconws = Convert.ToString(data["tcdconws"]);
                if (tcdconws.Equals("0"))
                {
                    LinearDimension dim7 = new LinearDimension(new Line(v80, v81), (v9.X - v80.X + offset) / 2.0, 270, dimensionStyle);
                    dim7.UserText = "DMM = " + Math.Round(dmm / scale, 2);
                    dxf.AddEntity(dim7);
                }
                else
                {
                    LinearDimension dim7 = new LinearDimension(new Line(v80, v81), (v9.X - v80.X + offset) / 2.0, 270, dimensionStyle);
                    dim7.UserText = "DMM = " + Math.Round(dmm / scale, 2) + "  " + tcdconws;
                    dxf.AddEntity(dim7);
                }

                //尺寸8
                LinearDimension dim8 = new LinearDimension(new Line(v46, v50), -offset / 2.0, 135, dimensionStyle);
                dim8.UserText = "DRVSC = " + Math.Round(drvsc / scale, 2);
                dxf.AddEntity(dim8);
                //填充
                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v47));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v49));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v50));
                hatchpoly1.Vertexes[1].Bulge = -Math.Tan(pi / 8);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v52));
                hatchpoly1.Vertexes[3].Bulge = -Math.Tan(pi / 8);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v53));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v55));
                hatchpoly1.Vertexes[5].Bulge = -Math.Tan(pi / 8);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v56));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v46));
                hatchpoly1.Vertexes[7].Bulge = -Math.Tan(pi / 8);
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 89, 2.5 * (td / 3.0), hline1, harc1, hatching);

                string l5;
                string kr;

                if (mc == 0) { l5 = "8P"; kr = "4°30′"; }
                else if (mc == 1) { l5 = "4P"; kr = "8°30′"; }
                else if (mc == 2) { l5 = "2P"; kr = "17°"; }
                else if (mc == 3) { l5 = "6P"; kr = "6°"; }
                else { l5 = ""; kr = ""; }

                if (mc == 3 && tp > 2.5)
                {
                    Line line01 = new Line(fun.Polar(v80, pi, 4), fun.Polar(v81, pi, 4)); fun.drawBline(dxf, line01, 0.3, contour);
                }
                if (mc == 1 && tp > 2.5)
                {
                    Line line01 = new Line(fun.Polar(v80, pi, 4), fun.Polar(v81, pi, 4)); fun.drawBline(dxf, line01, 0.3, contour);
                    Line line02 = new Line(fun.Polar(v80, pi, 6.5), fun.Polar(v81, pi, 6.5)); fun.drawBline(dxf, line02, 0.3, contour);
                }


              /*  LinearDimension dim00 = new LinearDimension(new Line(v3, v2), offset, 0, dimensionStyle);
                dim00.UserText = "TCL = " + l5;
                dxf.AddEntity(dim00);*/

             //   fun.jdbz2(dxf, new Line(v3, v4), new Line(v2, v3), offset, height, arrowsize, 0.6, "KAPR=" + kr, "", "");

                //图框
                if (isframe == 1)
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(v1.X - 210 + (v45.X + v8.Y - v1.X) / 2.00, v1.Y + 148.5), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);




            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

    }
}
